
function changeModelColorLoading(self, tiyData) {
  tiyData.tStatus.modifyModal.isLoading = false;
  self.$nextTick(function () {
    tiyData.tStatus.modifyModal.isLoading = true;
  });
}

export const init = (self, tiyData) => {
  tiyData.tPage.currentPage = 1;
  tiyData.tPage.stepNumber = 40;
  tiyData.tParam.postageName = '';
}

export const webList = (self, tiyData) => {
  self.$Spin.show();
  self.$apiOther.qureySysConfigArgs({
    pageNum:tiyData.tPage.currentPage,
    pageSize:tiyData.tPage.stepNumber,
    type:tiyData.tParam.searchParams.type
  }).then(function (response) {
      self.$Spin.hide();
      if (response.success) {
        tiyData.tParam.length = [];
        tiyData.tData.configArgList.splice(0,tiyData.tData.configArgList.length) ;
        let sysConfigPage = response.result;
        tiyData.tPage.total = sysConfigPage.total;
        tiyData.tPage.stepNumber = sysConfigPage.pageSize;
        if (sysConfigPage.list.length !==0){
          sysConfigPage.list.forEach(
            function (item) {
              tiyData.tData.configArgList.push(item);
            }
          );
        }

      } else {
        self.$Spin.hide();
        self.$Message.error(response.errorMessage);
      }
    });
};

export const saveConfigArg = (self, tiyData) => {
  self.$refs["configArgForm"].validate((valid) => {
    if (valid) {
      self.$Spin.show();
      tiyData.tStatus.modifyModal.isLoading = true;
      self.$apiOther.addModifySysConfigArg({
        id:tiyData.tParam.configArg.id,
        zhName:tiyData.tParam.configArg.zhName,
        enName:tiyData.tParam.configArg.enName,
        value:tiyData.tParam.configArg.value,
        status:tiyData.tParam.configArg.status ? 100 : -1,
        type:tiyData.tParam.configArg.type,
        description:tiyData.tParam.configArg.description,
      }).then(function (response) {
        self.$Spin.hide();
        changeModelColorLoading(self, tiyData);
        if (response.success) {
          tiyData.tStatus.modifyModal.isShow=false;
          webList(self, tiyData);
          self.$Message.success('提交成功!');
        } else {
          tiyData.tStatus.modifyModal.isLoading = false;
          self.$Message.error(response.errorMessage);
        }
      });
    }else {
      changeModelColorLoading(self,tiyData);
    }
  });

};

export const modifyConfigArg = (self, tiyData,index) => {
  self.$refs["configArgForm"].resetFields();
  let selectedConfigArg = tiyData.tData.configArgList[index];
  tiyData.tParam.configArg.id = selectedConfigArg.id;
  tiyData.tParam.configArg.zhName = selectedConfigArg.zhName;
  tiyData.tParam.configArg.enName = selectedConfigArg.enName;
  tiyData.tParam.configArg.value = selectedConfigArg.value;
  tiyData.tParam.configArg.status = (selectedConfigArg.status == 100);
  tiyData.tParam.configArg.type = selectedConfigArg.type;
  tiyData.tParam.configArg.description = selectedConfigArg.description;
  tiyData.tStatus.modifyModal.isShow=true;
  tiyData.tStatus.modifyModal.title="编辑在线参数";
};


export const deleteConfigArg = (self, tiyData,id) => {
  tiyData.tParam.deleteConfigArgId = id;
  tiyData.tStatus.actionModal.isShow=true;
  tiyData.tStatus.actionModal.title="删除在线参数";
};

export const webDeleteConfigArg = (self, tiyData,id) => {
  self.$Spin.show();
  self.$apiOther.deleteSysConfigArg({
    sysConfigArgId:tiyData.tParam.deleteConfigArgId
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      tiyData.tStatus.actionModal.isShow=false;
      webList(self, tiyData);
      self.$Message.success('提交成功!');
    } else {
      self.$Spin.hide();
      self.$Message.error(response.errorMessage);
    }
  });
};


